<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="审核类型" prop="oaDictConfirmType">
        <el-select v-model="queryParams.oaDictConfirmType" placeholder="请选择审核类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="表名" prop="tableName">
        <el-input
          v-model="queryParams.tableName"
          placeholder="请输入表名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="外键ID" prop="fkUuid">
        <el-input
          v-model="queryParams.fkUuid"
          placeholder="请输入外键ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人姓名" prop="attentionUserName">
        <el-input
          v-model="queryParams.attentionUserName"
          placeholder="请输入经办人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人ID" prop="fkAttentionUserId">
        <el-input
          v-model="queryParams.fkAttentionUserId"
          placeholder="请输入经办人ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人姓名" prop="confirmUserName">
        <el-input
          v-model="queryParams.confirmUserName"
          placeholder="请输入审核人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核人ID" prop="fkConfirmUserId">
        <el-input
          v-model="queryParams.fkConfirmUserId"
          placeholder="请输入审核人ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核时间">
        <el-date-picker
          v-model="daterangeConfirmDt"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="审核结果" prop="confirmResult">
        <el-select v-model="queryParams.confirmResult" placeholder="请选择审核结果" clearable size="small">
          <el-option
            v-for="dict in dict.type.oa_dict_confirm_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审核结果" prop="oaDictConfirmStatus">
        <el-input
          v-model="queryParams.oaDictConfirmStatus"
          placeholder="请输入审核结果"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['oa:confirm:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['oa:confirm:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['oa:confirm:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['oa:confirm:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="confirmList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="confirmUuid" />
      <el-table-column label="审核类型" align="center" prop="oaDictConfirmType" />
      <el-table-column label="表名" align="center" prop="tableName" />
      <el-table-column label="外键ID" align="center" prop="fkUuid" />
      <el-table-column label="业务内容" align="center" prop="businessContent" />
      <el-table-column label="经办人姓名" align="center" prop="attentionUserName" />
      <el-table-column label="经办人ID" align="center" prop="fkAttentionUserId" />
      <el-table-column label="审核人姓名" align="center" prop="confirmUserName" />
      <el-table-column label="审核人ID" align="center" prop="fkConfirmUserId" />
      <el-table-column label="审核时间" align="center" prop="confirmDt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.confirmDt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核结果" align="center" prop="confirmResult">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.oa_dict_confirm_status" :value="scope.row.confirmResult"/>
        </template>
      </el-table-column>
      <el-table-column label="审核意见" align="center" prop="confirmNote" />
      <el-table-column label="审核结果" align="center" prop="oaDictConfirmStatus" />
      <el-table-column label="备注" align="center" prop="note" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['oa:confirm:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['oa:confirm:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改审核对话框 -->
    <el-dialog v-dialogDrag v-dialogDragWidth :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="审核类型" prop="oaDictConfirmType">
          <el-select v-model="form.oaDictConfirmType" placeholder="请选择审核类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="表名" prop="tableName">
          <el-input v-model="form.tableName" placeholder="请输入表名" />
        </el-form-item>
        <el-form-item label="外键ID" prop="fkUuid">
          <el-input v-model="form.fkUuid" placeholder="请输入外键ID" />
        </el-form-item>
        <el-form-item label="业务内容" prop="businessContent">
          <el-input v-model="form.businessContent" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="经办人姓名" prop="attentionUserName">
          <el-input v-model="form.attentionUserName" placeholder="请输入经办人姓名" />
        </el-form-item>
        <el-form-item label="经办人ID" prop="fkAttentionUserId">
          <el-input v-model="form.fkAttentionUserId" placeholder="请输入经办人ID" />
        </el-form-item>
        <el-form-item label="审核人姓名" prop="confirmUserName">
          <el-input v-model="form.confirmUserName" placeholder="请输入审核人姓名" />
        </el-form-item>
        <el-form-item label="审核人ID" prop="fkConfirmUserId">
          <el-input v-model="form.fkConfirmUserId" placeholder="请输入审核人ID" />
        </el-form-item>
        <el-form-item label="审核时间" prop="confirmDt">
          <el-date-picker clearable size="small"
            v-model="form.confirmDt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核结果" prop="confirmResult">
          <el-select v-model="form.confirmResult" placeholder="请选择审核结果">
            <el-option
              v-for="dict in dict.type.oa_dict_confirm_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核意见" prop="confirmNote">
          <el-input v-model="form.confirmNote" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="审核结果" prop="oaDictConfirmStatus">
          <el-input v-model="form.oaDictConfirmStatus" placeholder="请输入审核结果" />
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listConfirm, getConfirm, delConfirm, addConfirm, updateConfirm } from "@/api/oa/confirm";

export default {
  name: "Confirm",
  dicts: ['oa_dict_confirm_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 审核表格数据
      confirmList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangeConfirmDt: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        oaDictConfirmType: null,
        tableName: null,
        fkUuid: null,
        businessContent: null,
        attentionUserName: null,
        fkAttentionUserId: null,
        confirmUserName: null,
        fkConfirmUserId: null,
        confirmDt: null,
        confirmResult: null,
        confirmNote: null,
        oaDictConfirmStatus: 'pass',
        note: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        oaDictConfirmType: [
          { required: true, message: "审核类型不能为空", trigger: "change" }
        ],
        tableName: [
          { required: true, message: "表名不能为空", trigger: "blur" }
        ],
        fkUuid: [
          { required: true, message: "外键ID不能为空", trigger: "blur" }
        ],
        businessContent: [
          { required: true, message: "业务内容不能为空", trigger: "blur" }
        ],
        attentionUserName: [
          { required: true, message: "经办人姓名不能为空", trigger: "blur" }
        ],
        fkAttentionUserId: [
          { required: true, message: "经办人ID不能为空", trigger: "blur" }
        ],
        confirmUserName: [
          { required: true, message: "审核人姓名不能为空", trigger: "blur" }
        ],
        fkConfirmUserId: [
          { required: true, message: "审核人ID不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询审核列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeConfirmDt && '' != this.daterangeConfirmDt) {
        this.queryParams.params["beginConfirmDt"] = this.daterangeConfirmDt[0];
        this.queryParams.params["endConfirmDt"] = this.daterangeConfirmDt[1];
      }
      listConfirm(this.queryParams).then(response => {
        this.confirmList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        confirmUuid: null,
        oaDictConfirmType: null,
        tableName: null,
        fkUuid: null,
        businessContent: null,
        attentionUserName: null,
        fkAttentionUserId: null,
        confirmUserName: null,
        fkConfirmUserId: null,
        confirmDt: null,
        confirmResult: null,
        confirmNote: null,
        oaDictConfirmStatus: null,
        note: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeConfirmDt = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.confirmUuid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加审核";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const confirmUuid = row.confirmUuid || this.ids
      getConfirm(confirmUuid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改审核";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.confirmUuid != null) {
            updateConfirm(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addConfirm(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const confirmUuids = row.confirmUuid || this.ids;
      this.$modal.confirm('是否确认删除审核编号为"' + confirmUuids + '"的数据项？').then(function() {
        return delConfirm(confirmUuids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('oa/confirm/export', {
        ...this.queryParams
      }, `oa_confirm.xlsx`)
    }
  }
};
</script>
